#include "PID.h"


float PP=0.1,II=0.05,DD=0;

double SumError=0,PrevError=0,LastError=0;
int dError=0,Error=0;

void PID_init(void)
{
	Error=0;SumError=0;LastError=0;
}

void PIDcompute(unsigned int Target,unsigned int Real)
{
   float j=0.0,i;
      
		Error =(Target-Real);   
    Error=	Error;

		 SumError +=Error;		
	   if(SumError<6)	SumError=6;
     else if(SumError>128000)SumError=128000+50;
	    
		i=PP;
		j=Error*i;
		i=II;
		j=j+SumError*i;

	 if(j>PWM_PERIOD)OutPwmValue=PWM_PERIOD;
	 else if(j<1)OutPwmValue=1;
	 else OutPwmValue=j;
	 
	 UPPWM();
}

